package org.fyp.synchrona.core.impl;


import org.fyp.synchrona.core.info.impl.CommonProfileObject;
import org.fyp.synchrona.services.utill.BloggerObj;
import org.fyp.synchrona.services.utill.FacebookObj;
import org.fyp.synchrona.services.utill.MoodleObj;
import org.fyp.synchrona.services.utill.TwitterObj;

public class ServiceObjCreator {
	
	private static ServiceObjCreator serviceObjc;
	
	private ServiceObjCreator(){
		
	}

	public static synchronized ServiceObjCreator getServiceObjectCreatorObj(){
		if(serviceObjc==null){
			serviceObjc = new ServiceObjCreator();
			return serviceObjc;
		}else{
			return serviceObjc;
		}
	}
	
	public BloggerObj createBlogerObj(CommonProfileObject cpo){
		
		BloggerObj b = new BloggerObj();
		if(cpo.getEMAIL()!=null){
			b.setEmail(cpo.getEMAIL());
		}
				
		/**
		 * there are two four ways to create user name or display name
		 * those ways are dirived using firstname , middlename, lastname ,fullname attributes
		 **/
		
		if(cpo.getUSER_NAME()!=null){
			b.setDisplayname(cpo.getUSER_NAME());			
		}else if(cpo.getFIRST_NAME()!=null){
			b.setDisplayname(cpo.getFIRST_NAME());
		}else if(cpo.getLAST_NAME()!=null){
			b.setDisplayname(cpo.getLAST_NAME());
		}else if(cpo.getFULL_NAME()!=null){
			b.setDisplayname(cpo.getFULL_NAME());
		}
		
		/*there are two ways to create first name using firstname and part of full name*/
		if(cpo.getFIRST_NAME()!=null){
			b.setFirstname(cpo.getFIRST_NAME());
		}else if(cpo.getFULL_NAME()!=null){
			b.setFirstname(cpo.getFULL_NAME().substring(0, cpo.getFULL_NAME().indexOf(" ")));			
		}
		
		/*this need to be discussed*/
		if(cpo.getSEX()!=null){
			if(cpo.getSEX().equals("1")){
				b.setSex("MALE");
			}else{
				b.setSex("FEMALE");
			}
			
		}
		
		/**/
		if(cpo.getBIRTH_DAY()!=null){
			b.setBirthday(cpo.getBIRTH_DAY());
		}
		/**/
		if(cpo.getBIRTH_MONTH()!=null){
			b.setBirthmonth(cpo.getBIRTH_MONTH());
		}
		/**/
		if(cpo.getBIRTH_YEAR()!=null){
			b.setBirthyear(cpo.getBIRTH_YEAR());
		}
		
		if(cpo.getWEBSITE()!=null){
			b.setUrl(cpo.getWEBSITE());
		}
		
		/**/
		if(cpo.getCITY()!=null){
			b.setCity(cpo.getCITY());
		}else if(cpo.getCURRENT_COUNTRY_CITY()!=null){
			b.setCity(cpo.getCURRENT_COUNTRY_CITY().substring(0, cpo.getCURRENT_COUNTRY_CITY().indexOf(",")));
		}
		
		/**/
		if(cpo.getCOUNTRY()!=null){
			b.setCountry(cpo.getCOUNTRY());
		}else if(cpo.getCURRENT_COUNTRY_CITY()!=null){
			b.setCountry(cpo.getCURRENT_COUNTRY_CITY().substring(cpo.getCURRENT_COUNTRY_CITY().indexOf(",")));
		}
		
		
		return b;
	}
	
	public FacebookObj createFbObj(CommonProfileObject cpo){
		
		return null;
	}
	
	public TwitterObj createTwitterObj(CommonProfileObject cpo){
		
		return null;
	}
	
	public MoodleObj createMoodleObj(CommonProfileObject cpo){
		
		return null;
	}
}
